package com.baichang.taoshunda.controller;

import com.baichang.framework.controller.IController;
import com.baichang.framework.controller.IPageController;
import com.baichang.framework.controller.WebBaseController;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.framework.model.Page;
import com.baichang.framework.security.entity.SAdmin;
import com.baichang.taoshunda.ControllerConstants;
import com.baichang.taoshunda.service.CashService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;

/**
 * 提现表
 */

@Controller
@RequestMapping(ControllerConstants.CASH)
public class CashController extends WebBaseController {
    @Autowired
    private CashService cashService;

    @RequestMapping("/busscash")
    public String busscash(HttpServletRequest request, HttpServletResponse response) {
        return "/taoshunda/cash/busscash";
    }

    @RequestMapping("/delivercash")
    public String delivercash(HttpServletRequest request, HttpServletResponse response) {
        return "/taoshunda/cash/delivercash";
    }

    @RequestMapping("/cashrecord")
    public String cashrecord(HttpServletRequest request, HttpServletResponse response) {
        return "/taoshunda/cash/index";
    }


    /**
     * 商家提现列表
     *
     * @param request
     * @param response
     */
    @RequestMapping("/busscashQuery")
    public void busscashQuery(HttpServletRequest request, HttpServletResponse response) {
        initPage(request, response, new IPageController() {
            @Override
            public Page initPage(HttpServletRequest request, HttpServletResponse httpServletResponse) throws ServiceException {
                String bussName = getString(request, "bussName", "");
                String startTime = getString(request, "start", "");
                String endTime = getString(request, "end", "");
                int cashstatus = getInt(request, "cashstatus", 0);
                int companyId = getInt(request, "companyId", 0);
                return cashService.busscashQuery(nowPage, pageSize, bussName, startTime, endTime, cashstatus, companyId);
            }
        });
    }


    /**
     * 商家提现列表的导出  busscashQueryExport
     *
     * @param request
     * @param response
     */
    @RequestMapping("/busscashQueryExport")
    public void busscashQueryExport(HttpServletRequest request, HttpServletResponse response) {
        init(request, response, new IController() {
            @Override
            public Object initData(HttpServletRequest request, HttpServletResponse response) throws ServiceException {
                String ids = getString(request, "ids", "");

                return cashService.busscashQueryExport(response, ids);
            }
        });
    }

    /**
     * 提现审核通过与审核失败
     */
    @RequestMapping("/audit")
    public void audit(HttpServletRequest request, HttpServletResponse response) {
        init(request, response, new IController() {
            @Override
            public Object initData(HttpServletRequest request, HttpServletResponse httpServletResponse) throws ServiceException {
                int id = getInt(request, "id", 0);
                int state = getInt(request, "state", 0);
                SAdmin sAdmin = (SAdmin) request.getSession().getAttribute("SESSION_USER_WEB");
                String auditPersonName = sAdmin.getUsername();
                String auditReason = getString(request, "reason", "");
                Integer companyId = getInt(request, "companyId", 0);
                BigDecimal money = BigDecimal.valueOf(getDouble(request, "money", 0));
                Integer deliveryId = getInt(request, "deliveryId", 0);
                return cashService.audit(id, state, auditPersonName, auditReason, companyId, money, deliveryId);
            }
        });
    }


    /**
     * 配送员提现列表
     *
     * @param request
     * @param response
     */
    @RequestMapping("/delivercashQuery")
    public void delivercashQuery(HttpServletRequest request, HttpServletResponse response) {
        initPage(request, response, new IPageController() {
            @Override
            public Page initPage(HttpServletRequest request, HttpServletResponse httpServletResponse) throws ServiceException {
                String bussName = getString(request, "bussName", "");
                String startTime = getString(request, "start", "");
                String endTime = getString(request, "end", "");
                int cashstatus = getInt(request, "cashstatus", 0);
                int deliverId = getInt(request, "deliverId", 0);
                return cashService.delivercashQuery(nowPage, pageSize, bussName, startTime, endTime, cashstatus, deliverId);
            }
        });
    }


    /**
     * 配送提现列表的导出
     *
     * @param request
     * @param response
     */
    @RequestMapping("/delivercashQueryExport")
    public void delivercashQueryExport(HttpServletRequest request, HttpServletResponse response) {
        init(request, response, new IController() {
            @Override
            public Object initData(HttpServletRequest request, HttpServletResponse response) throws ServiceException {
                String ids = getString(request, "ids", "");
                return cashService.delivercashQueryExport(response, ids);
            }
        });
    }


    /**
     * 提现列表的查询
     *
     * @param request
     * @param response
     */
    @RequestMapping("/indexQuery")
    public void indexQuery(HttpServletRequest request, HttpServletResponse response) {
        initPage(request, response, new IPageController() {
            @Override
            public Page initPage(HttpServletRequest request, HttpServletResponse httpServletResponse) throws ServiceException {
                String bussName = getString(request, "bussName", "");
                String checkBusinessName = getString(request, "checkBusinessName", "");
                String checkDeliveryName = getString(request, "checkDeliveryName", "");
                int cashstatus = getInt(request, "cashstatus", 0);
                String startTime = getString(request, "start", "");
                String endTime = getString(request, "end", "");
                return cashService.indexQuery(nowPage, pageSize, bussName, cashstatus, startTime, endTime,checkBusinessName,checkDeliveryName);
            }
        });
    }
}
